﻿using System.Collections.Generic;
using System.Linq;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System;
using System.ComponentModel.DataAnnotations.Schema;

namespace AesApplication.Models
{
    public class AesContext : DbContext
    {
        public AesContext() 
            : base("DefaultConnection")
        { }

        public DbSet<Store> Stores { get; set; }
        public DbSet<StoreManager> StoreManagers { get; set; }
        public DbSet<Department> Departments { get; set; }
        public DbSet<DepartmentManager> DepartmentManagers { get; set; }
        public DbSet<DepartmentSpecialist> DepartmentSpecialists { get; set; }
        public DbSet<Job> Jobs { get; set; }
        public DbSet<Application> Applications { get; set; }
        public DbSet<Question> Questions { get; set; }
        public DbSet<Answer> Answers { get; set; }
        public DbSet<Questionnaire> Questionnaires { get; set; }

        // Returns query of Departments managed by given user ID.
        public IQueryable<Department> DepartmentsManagedBy(int userId)
        {
            return from dept in Departments
                   where (dept.Managers.Any(manager => manager.UserID == userId))
                   select dept;
        }

        // Returns query of Departments assigned to a given user ID. (Specialist)
        public IQueryable<Department> DepartmentsAssignedTo(int inUserID)
        {
            return from dept in Departments
                   where (dept.Specialists.Any(specialist => specialist.UserID == inUserID))
                   select dept;
        }

        // Returns query of jobs that need approval. (StoreManager)
        public IQueryable<Job> JobsAwaitingApproval(int inUserID)
        {
            return from store in Stores
                   from dept in Departments
                   from job in Jobs
                   where (store.ID == dept.StoreID && dept.ID == job.DepartmentID && job.Status == JobStatus.AwaitingActivation)
                   select job;
        }


        //Returns query of Stores assigned to a given user ID. (StoreManager)
        public IQueryable<Store> StoresAssignedTo(int inUserID)
        {
            return from store in Stores
                   where (store.StoreManagers.Any(storemanager => storemanager.UserID == inUserID))
                   select store;
        }

        // Returns query of Questionnaires that are not attached to any Job.
        public IQueryable<Questionnaire> UnattachedQuestionnaires()
        {
            return from qnaire in Questionnaires
                   where (!Jobs.Any(job => job.Questionnaire.ID == qnaire.ID))
                   select qnaire;
        }
    }

    public class Store
    {
        public int ID { get; set; }
        public string Name { get; set; }

        // A department has many hiring specialists
        public virtual ICollection<StoreManager> StoreManagers { get; set; }

        // A Store has many Departments.
        public virtual ICollection<Department> Departments { get; set; }
    }

    public class Department
    {
        public int ID { get; set; }
        public string Name { get; set; }

        // A Department belongs to one Store.
        public int StoreID { get; set; } // Entity framework recognizes this as a Store reference
        public virtual Store Store { get; set; }

        // A department has many hiring specialists
        public virtual ICollection<DepartmentSpecialist> Specialists { get; set; }
        // A Department has many hiring managers
        public virtual ICollection<DepartmentManager> Managers { get; set; }
        // A Department has many Jobs.
        public virtual ICollection<Job> Jobs { get; set; }

        // Returns whether a given user ID is a manager of this department.
        // (i.e. has permission to request jobs and hire applicants.)
        public bool IsManagedBy(int userId)
        {
            return Managers.Any(x => x.UserID == userId);
        }
    }

    // Intermediate table for relating Departments to their Hiring specialists.
    // Creates a many-to-many relationship between Departments and UserProfiles.
    public class DepartmentSpecialist
    {
        [Key, Column(Order = 0)]
        public int DepartmentID { get; set; }
        [Key, Column(Order = 1)]
        public int UserID { get; set; }

        public virtual Department Department { get; set; }
        public virtual UserProfile User { get; set; }
    }

    // Intermediate table for relating Stores to their Store Managers.
    // Creates a many-to-many relationship between Departments and UserProfiles.
    public class StoreManager
    {
        [Key, Column(Order = 0)]
        public int StoreID { get; set; }
        [Key, Column(Order = 1)]
        public int UserID { get; set; }

        public virtual Store Store { get; set; }
        public virtual UserProfile User { get; set; }
    }

    // Intermediate table for relating Departments to their hiring managers.
    // Creates a many-to-many relationship between Departments and UserProfiles.
    public class DepartmentManager
    {
        [Key, Column(Order = 0)]
        public int DepartmentID { get; set; }
        [Key, Column(Order = 1)]
        public int UserID { get; set; }

        public virtual Department Department { get; set; }
        public virtual UserProfile User { get; set; }
    }

    public class Job
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public JobStatus Status { get; set; }
        public string Requester { get; set; }
        public System.DateTime RequestDate { get; set; }

        public int Quantity { get; set; }

        [DisplayName("Short Description")]
        public string ShortDescription { get; set; }

        [DisplayName("Long Description")]
        public string LongDescription { get; set; }

        [DisplayName("Start Date")]
        public System.DateTime StartDate { get; set; }

        [DisplayName("End Date")]
        public System.DateTime EndDate { get; set; }



        // A Job belongs to one Department.
        public int DepartmentID { get; set; }
        public virtual Department Department { get; set; }

        // A Job has one Questionnaire.
        public int? QuestionnaireID { get; set; } // null for no questionnaire (only the standard questions will appear)
        public virtual Questionnaire Questionnaire { get; set; }

        // A Job has many Applications.
        public virtual ICollection<Application> Applications { get; set; }
    }

    public enum JobStatus
    {
        AwaitingActivation,
        //Exmaple : Hiring Manger requests for new positions in Department.

        Denied,
        //Example : Hiring Manager Requests Job, Store Manager denies

        Active,
        //Example : Store manager selects "Confirm", Job becomes active.

        Closed,
        //Example : Hiring Manager Hire's Applicants, and the job is filled. Or position is removed from list.

    }

    public enum QuestionType
    {
        OneLine,
        // example:
        // Text="What?"
        // ExpectedAnswer="This" (not case-sensitive)

        Essay,
        // example:
        // Text="What?"
        // ExpectedAnswer="That" (not case-sensitive)

        Numeric,
        // example:
        // Text="How much?"
        // ExpectedAnswer="3" (also accepts 3.0, 03.00, etc.)

        TrueFalse,
        // example:
        // Text="True or false?"
        // ExpectedAnswer="T"

        MultipleChoice,
        // example:
        // Text="Which?{A}Answer 1{B}Answer 2"
        // ExpectedAnswer="A"
    }

    // IMPORTANT: Once a Question is created, it should not change.
    // If a Question changes, Applications that reference it will become invalid.
    public class Question
    {
        public int ID { get; set; }
        public int Number { get; set; } // questions are ordered 1, 2, 3...
        public QuestionType Type { get; set; }
        public string Text { get; set; }
        public string ExpectedAnswer { get; set; } // format depends on type, see above
        public bool AutoScreen { get; set; } // Whether to auto-screen this question

        public string GetDisplayText()
        {
            if (Type == QuestionType.MultipleChoice)
            {
                return Text.Split('{')[0];
            }
            else
            {
                return Text;
            }
        }

        public struct MultipleChoiceOption
        {
            public string Name;
            public string Text;
        }

        public IEnumerable<MultipleChoiceOption> GetMultipleChoiceOptions()
        {
            if (Type != QuestionType.MultipleChoice)
            {
                throw new InvalidOperationException("Question must be multiple-choice.");
            }

            IEnumerable<string> optionStrings = Enumerable.Skip(Text.Split('{'), 1);
            return optionStrings.Select(s => {
                string[] nameAndText = s.Split('}');
                return new MultipleChoiceOption { Name = nameAndText[0], Text = nameAndText[1] };
            });
        }

        // Question belongs to one Questionnaire.
        public virtual Questionnaire Questionnaire { get; set; }
    }

    public class Answer
    {
        public int ID { get; set; }
        public string Text { get; set; }

        // Answer belongs to one Application.
        public virtual Application Application { get; set; }
        // Answer answers one Question.
        public virtual Question Question { get; set; }
    }

    public class Questionnaire
    {
        public int ID { get; set; }
        //The name of the questionnaire
        public string Name { get; set; }
        // A Questionnaire has many Questions.
        public virtual ICollection<Question> Questions { get; set; }
    }

    public enum ApplicationStatus
    {
        AutoRejected, // failed auto-screening
        AwaitingHumanScreening, // passed auto-screening, awaiting human (phone) screening
        HumanRejected, // failed human (phone) screening
        AwaitingHire, // passed all screening and awaiting hiring decision
        NotHired, // passed all screening but not hired
        Hired, // passed all screening and hired
    }

    public class Application
    {
        public Application()
        {
            Answers = new List<Answer>();
        }

        [Key]
        public int ID { get; set; }
        [Required]
        public ApplicationStatus Status { get; set; }
        
        [Required]
        [DisplayName("First Name")]
        public string FirstName { get; set; }
        
        [Required]
        [DisplayName("Last Name")]
        public string LastName { get; set; }
        
        [Required]
        //Apparently dynamic expressions are not allowed for models in Entity, so the line below won't work...
        //[Range(typeof(DateTime), DateTime.Today.AddYears(-130).ToString(), DateTime.Today.AddYears(-16).ToString())]
        //However a hard coded string does, this possibly will change...
        [Range(typeof(DateTime), "3/28/1885", "3/28/1999")]
        [DisplayName("Birth Date")]
        public System.DateTime BirthDate { get; set; }

        [Required]
        public string Address { get; set; }

        [Required]
        public string City { get; set; }

        [Required]
        [MinLength(2)]
        public string State { get; set; }

        [Required]
        [MinLength(5)]
        [MaxLength(10)]
        public string Zip { get; set; }

        public string HiringSpecialist { get; set; }
        public string HiringSpecialistComment { get; set; }
        public string HiringManager { get; set; }
        public string HiringManagerComment { get; set; }

        // DataType annotations cause html engine to generate textarea instead of single-line text.
        [DataType(DataType.MultilineText)]
        [DisplayName("Work History")]
        public string WorkHistory { get; set; }

        [DataType(DataType.MultilineText)]
        public string Education { get; set; }

        // An Application has many Answers.
        public virtual ICollection<Answer> Answers { get; set; }

        // An Application belongs to one Job.
        public int JobID { get; set; }
        public virtual Job Job { get; set; }
    }

    // XXX: Initialize database with some test data
    // See: http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application
    // This will reset the database every time the server is run!
    // To avoid this, use DropCreateDatabaseIfModelChanges or set up Code First Migrations.
    public class Initializer : System.Data.Entity.DropCreateDatabaseAlways<AesContext>
    {
        protected override void Seed(AesContext context)
        {
            //var profiles = new List<UserProfile> {
            //    new UserProfile { UserId = 1, UserName="HiringSpecialist" }, // ID 1
            //    new UserProfile { UserId = 2, UserName="StaffingExpert"}, // ID 2
            //    new UserProfile { UserId = 3, UserName="StoreManager" }, // ID 3
            //    new UserProfile { UserId = 4, UserName="HiringManager" }, // ID 4
            //    new UserProfile { UserId = 5, UserName="IT"}, // ID 5
            //};


            // =================== Stores ============================= //

            string storeAut = "Autumn Avenue";
            string storeWorth = "Worthington Way";
            string storeHamp = "Hampshire Highway";
 

            var stores = new List<Store> {
                new Store { Name=storeAut },    // ID 1
                new Store { Name=storeWorth },  // ID 2
                new Store { Name=storeHamp },   // ID 3
            };
            stores.ForEach(store => context.Stores.Add(store));
            context.SaveChanges();

            // =================== Departments ============================= //

            string departmentElec = "Electronics";
            string departmentMens = "Men's Wear";
            string departmentWomens = "Women's Wear";
            string departmentToys = "Toys";
            string departmentFood = "Food";
            string departmentTools = "Tools";
            string departmentFurniture = "Furniture";
            

            var depts = new List<Department> {
                // Autumn Avenue
                new Department { StoreID=(from store in context.Stores where store.Name == storeAut select store.ID).FirstOrDefault(), Name=departmentElec },       // ID 1
                new Department { StoreID=(from store in context.Stores where store.Name == storeAut select store.ID).FirstOrDefault(), Name=departmentMens },       // ID 2
                new Department { StoreID=(from store in context.Stores where store.Name == storeAut select store.ID).FirstOrDefault(), Name=departmentWomens },     // ID 3
                // Worthington Way
                new Department { StoreID=(from store in context.Stores where store.Name == storeWorth select store.ID).FirstOrDefault(), Name=departmentElec },     // ID 4
                new Department { StoreID=(from store in context.Stores where store.Name == storeWorth select store.ID).FirstOrDefault(), Name=departmentMens },     // ID 5
                new Department { StoreID=(from store in context.Stores where store.Name == storeWorth select store.ID).FirstOrDefault(), Name=departmentWomens },   // ID 6
                new Department { StoreID=(from store in context.Stores where store.Name == storeWorth select store.ID).FirstOrDefault(), Name=departmentToys },     // ID 7
                // Hampshire Highway
                new Department { StoreID=(from store in context.Stores where store.Name == storeHamp select store.ID).FirstOrDefault(), Name=departmentFood },      // ID 8
                new Department { StoreID=(from store in context.Stores where store.Name == storeHamp select store.ID).FirstOrDefault(), Name=departmentTools },     // ID 9
                new Department { StoreID=(from store in context.Stores where store.Name == storeHamp select store.ID).FirstOrDefault(), Name=departmentFurniture }, // ID 10
            };
            depts.ForEach(dept => context.Departments.Add(dept));
            context.SaveChanges();


            // =================== Questionnaire's ============================= //
            var qnaires = new List<Questionnaire> {
                new Questionnaire
                {
                    Name = "EEO",
                    Questions = new List<Question> {
                            new Question {
                                Number=1,
                                Type=QuestionType.MultipleChoice,
                                Text="What is your Gender?{A}Male{B}Female{C}Choose not to identify",
                            },
                            new Question {
                                Number=2,
                                Type=QuestionType.MultipleChoice,
                                Text="What is your race?{A}Caucasian{B}Hispanic or Latino{C}African{D}Native{E}Choose not identify",
                            },
                            new Question {
                                Number=3,
                                Type=QuestionType.MultipleChoice,
                                Text="Are you a retired vetran or currently a member of the armed forces?{A}Yes{B}No{C}Choose to not identify.",
                            },
                            new Question {
                                Number=4,
                                Type=QuestionType.MultipleChoice,
                                Text="Are you considered disabled or handicapped?{A}Yes{B}No{C}Choose to not identify",
                            },
                        },
                    },
                new Questionnaire
                {
                    Name="Cook",
                    Questions=new List<Question> {
                            new Question {
                                Number=1,
                                Type=QuestionType.TrueFalse,
                                Text="I have cooked at least once in my life.",
                                ExpectedAnswer="T"
                            },
                            new Question {
                                Number=2,
                                Type=QuestionType.Numeric,
                                Text="How many teaspoons are in a tablespoon?",
                                ExpectedAnswer="3"
                            },
                            new Question {
                                Number=3,
                                Type=QuestionType.MultipleChoice,
                                // This is the format of multiple-choice questions.
                                Text="Is a potato a fruit or a vegetable?{A}Fruit{B}Vegetable",
                                ExpectedAnswer="B"
                            },
                            new Question {
                                Number=4,
                                Type=QuestionType.OneLine,
                                Text="In one word, what is the difference between fruits and vegetables?",
                                ExpectedAnswer="Seeds"
                            },
                            new Question {
                                Number=5,
                                Type=QuestionType.Essay,
                                Text="Type your favorite salad recipe.",
                                ExpectedAnswer="", // No expected answer
                            },
                         },
                    },
            };
            
            qnaires.ForEach(questionnaire => context.Questionnaires.Add(questionnaire));
            context.SaveChanges();
  


            // =================== Jobs ============================= //

            string jobCashier = "Cashier";
            string jobCook = "Cook";
            string jobAssociate = "Associate";
            string jobCustodian = "Custodian";
            string jobStockHandler = "Stock Handler";
           
            var jobs = new List<Job>();
            // Autumn Avenue -> Electronics
            jobs.Add(new Job {
                DepartmentID = 
                (from department in context.Departments from store in context.Stores
                     where department.StoreID == store.ID && 
                     store.Name == storeAut &&
                     department.Name == departmentElec
                     select department.ID).FirstOrDefault(),
                Title = jobCashier,
                Status = JobStatus.AwaitingActivation,
                RequestDate = new System.DateTime(2015, 1, 4),
                Requester = "HiringManager",
                Quantity=1,
                ShortDescription = "Cashier for Electronics.",
                LongDescription = "We are hiring a sales associate for Electronics. Video gaming experience preferred.",
                StartDate = new System.DateTime(2015, 1, 5),
                EndDate = new System.DateTime(2015, 8, 30),
                });
                
            // Hampshire Highway -> Food
            jobs.Add(new Job {
                DepartmentID =
                (from department in context.Departments from store in context.Stores
                    where department.StoreID == store.ID && 
                    store.Name == storeHamp &&
                    department.Name == departmentFood
                    select department.ID).FirstOrDefault(),
                Title=jobCook,
                Status = JobStatus.Active,
                RequestDate = new System.DateTime(2015, 1, 4),
                Requester = "HiringManager",
                Quantity=2,
                ShortDescription="We need two cooks.",
                LongDescription="We really, really, really, really, really need a couple cooks.",
                StartDate=new System.DateTime(2015, 1, 1),
                EndDate=new System.DateTime(2015, 6, 30),
                Questionnaire = new Questionnaire
                {
                    Name = "Cook",
                    Questions = new List<Question> {
                            new Question {
                                Number=1,
                                Type=QuestionType.TrueFalse,
                                Text="I have cooked at least once in my life.",
                                ExpectedAnswer="T"
                            },
                            new Question {
                                Number=2,
                                Type=QuestionType.Numeric,
                                Text="How many teaspoons are in a tablespoon?",
                                ExpectedAnswer="3"
                            },
                            new Question {
                                Number=3,
                                Type=QuestionType.MultipleChoice,
                                // This is the format of multiple-choice questions.
                                Text="Is a potato a fruit or a vegetable?{A}Fruit{B}Vegetable",
                                ExpectedAnswer="B"
                            },
                            new Question {
                                Number=4,
                                Type=QuestionType.OneLine,
                                Text="In one word, what is the difference between fruits and vegetables?",
                                ExpectedAnswer="Seeds"
                            },
                            new Question {
                                Number=5,
                                Type=QuestionType.Essay,
                                Text="Type your favorite salad recipe.",
                                ExpectedAnswer="", // No expected answer
                            },
                         },
                },   
                });

            // Worthington Way -> Electronics
            jobs.Add(new Job {
                DepartmentID =
                    (from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && 
                         store.Name == storeWorth &&
                         department.Name == departmentElec
                         select department.ID).FirstOrDefault(),
                Title=jobAssociate,
                Status = JobStatus.Active,
                RequestDate = new System.DateTime(2015, 1, 4),
                Requester = "HiringManager",
                Quantity=1,
                ShortDescription="Unloads new stock, organizes aisle",
                LongDescription="Keeps track of stock, organizes products. Helps satsify customer inquiries.",
                StartDate = new System.DateTime(2015,6,1),
                EndDate = new System.DateTime(2015,9,20),
                });

            // Hampshire Highway -> Food
            jobs.Add(new Job {
                DepartmentID =
                    (from department in context.Departments from store in context.Stores
                     where department.StoreID == store.ID && 
                     store.Name == storeHamp &&
                     department.Name == departmentFood
                     select department.ID).FirstOrDefault(),
                Title=jobCustodian,
                Status = JobStatus.Active,
                RequestDate = new System.DateTime(2015, 1, 4),
                Requester = "HiringManager",
                Quantity=1,
                ShortDescription="Qualified cleanup manager.", 
                LongDescription="Maintains restrooms, performs accident cleanup, and wipes windows.", 
                StartDate = new System.DateTime(2015,04,08),
                EndDate = new System.DateTime(2015,06,28),
                });

            //Worthington Way -> Women's Wear
            jobs.Add(new Job {
                DepartmentID =
                    (from department in context.Departments from store in context.Stores
                     where department.StoreID == store.ID && 
                     store.Name == storeWorth &&
                     department.Name == departmentWomens
                     select department.ID).FirstOrDefault(),
                Title=jobStockHandler,
                Status = JobStatus.Active,
                RequestDate = new System.DateTime(2015, 1, 4),
                Requester = "HiringManager",
                Quantity=1,
                ShortDescription="Unloads new stock, scans in new items",
                LongDescription="Unloads new inventory from trucks. Unloads pallets and places items on shelves. Disposes of pallets and other shipping materials.",
                StartDate = new System.DateTime(2015,6,3),
                EndDate = new System.DateTime(2015,10,1),
                });

            jobs.ForEach(job => context.Jobs.Add(job));
            context.SaveChanges();


            // =================== Appications ============================= //

            string addInfinite = "1 Infinite Loop";
            string addHacker = "1 Hacker Way";
            string addYourHouse = "Your House";
            string addSesame = "123 Sesame Street";
            string addOrteil = "http://orteil.dashnet.org/cookieclicker/";
            var applications = new List<Application>();

            applications.Add(
                new Application {
                    JobID =
                        (from job in context.Jobs from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && job.DepartmentID == department.ID && 
                            store.Name == storeAut &&
                            department.Name == departmentElec &&
                            job.Title == jobCashier
                         select job.ID).FirstOrDefault(),
                    Status=ApplicationStatus.AwaitingHumanScreening,
                    FirstName="John",
                    LastName="Doe",
                    BirthDate= new DateTime(1980,1,1),
                    Address=addInfinite,
                    HiringSpecialistComment="",
                    HiringSpecialist="",
                    HiringManager="",
                    HiringManagerComment="",
                    City="Cupertino",
                    State="CA",
                    Zip="95014",
                    WorkHistory="DevOps @ Apple - You know the really smart guys",
                    Education="Just Call me Doctor",
                    Answers=new List<Answer>(){},
                    });

            applications.Add(
                new Application {
                    JobID = 
                        (from job in context.Jobs from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && job.DepartmentID == department.ID && 
                            store.Name == storeAut &&
                            department.Name == departmentElec &&
                            job.Title == jobCashier
                         select job.ID).FirstOrDefault(),
                    Status = ApplicationStatus.AwaitingHumanScreening,
                    HiringSpecialist="",
                    HiringSpecialistComment="",
                    HiringManager = "",
                    HiringManagerComment = "",
                    FirstName="Jane",
                    LastName="Doe",
                    BirthDate= new DateTime(1981,1,1),
                    Address=addHacker,
                    City="Menlo Park",
                    State="CA",
                    Zip="94205",
                    WorkHistory="Development @ Facebook - The socialites",
                    Education="I know Mark.",
                    Answers=new List<Answer>(){},
                    });

            applications.Add(
                new Application {
                    JobID = 
                        (from job in context.Jobs from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && job.DepartmentID == department.ID && 
                            store.Name == storeWorth &&
                            department.Name == departmentWomens &&
                            job.Title == jobStockHandler
                         select job.ID).FirstOrDefault(),
                    Status=ApplicationStatus.AwaitingHire,
                    FirstName="Creepy",
                    HiringSpecialist="HiringSpecialist",
                    HiringSpecialistComment="This is a test comment",
                    HiringManager="",
                    HiringManagerComment = "",
                    LastName="Stalker",
                    BirthDate= new DateTime(1990,12,12),
                    Address=addYourHouse,
                    City="Your City",
                    State="XX",
                    Zip="10001",
                    WorkHistory="Taking Photos",
                    Education="...",
                    Answers=new List<Answer>(){},
                    });
                       
            applications.Add(
                new Application {
                    JobID = 
                        (from job in context.Jobs from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && job.DepartmentID == department.ID && 
                            store.Name == storeHamp &&
                            department.Name == departmentFood &&
                            job.Title == jobCook
                         select job.ID).FirstOrDefault(),
                    Status=ApplicationStatus.AwaitingHire,
                    HiringSpecialist = "HiringSpecialist",
                    HiringSpecialistComment = "Some more comments about this person that is important.",
                    HiringManager = "",
                    HiringManagerComment = "",
                    FirstName="Cookie",
                    LastName="Monster",
                    BirthDate= new DateTime(1950,1,1),
                    Address=addSesame,
                    City="New York",
                    State="NY",
                    Zip="10001",
                    WorkHistory="Eatting",
                    Education="Learned everything from TV",
                    Answers=new List<Answer>(){},
                    });

            applications.Add(
                new Application {
                    JobID = 
                        (from job in context.Jobs from department in context.Departments from store in context.Stores
                         where department.StoreID == store.ID && job.DepartmentID == department.ID && 
                            store.Name == storeHamp &&
                            department.Name == departmentFood &&
                            job.Title == jobCook
                         select job.ID).FirstOrDefault(),
                    Status=ApplicationStatus.AwaitingHire,
                    HiringSpecialist = "HiringSpecialist",
                    HiringSpecialistComment = "Some interesting comments",
                    HiringManager = "",
                    HiringManagerComment = "",
                    FirstName="Clicker",
                    LastName="Cookie",
                    BirthDate= new DateTime(1960,6,6),
                    Address=addOrteil,
                    City="Store",
                    State="CA",
                    Zip="94205",
                    WorkHistory="Click Click Click",
                    Education="More Clicking",
                    Answers=new List<Answer>(){},
                    });
      
            applications.ForEach(app => context.Applications.Add(app));
            context.SaveChanges();


        }
    }
}